package com.huanzhidadi.logaspect.controller;

import cn.hutool.http.HttpUtil;
import com.huanzhidadi.logaspect.annotation.Log;
import com.huanzhidadi.logaspect.annotation.ThirdLogAnno;
import com.huanzhidadi.logaspect.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 记录调用第三方接口的日志 101180101
 */
@Api(tags = "logThirdPartMethod")
@RestController
@RequestMapping(value = "logThirdPartMethod")
@Slf4j
public class LogThirdPartMethodController {

    @ApiOperation(value = "调用第三方天气接口")
    @RequestMapping(value = "/getWeather/{cityCode}", method = RequestMethod.POST)
    @Log(title = "方法级日志管理", businessType = BusinessType.THIRD)
    @ThirdLogAnno(serviceName = "调用第三方天气接口", bizCodeField = "PathVariable")
    public Map<String, String> getWeather(@PathVariable String cityCode) {
        String url = "http://t.weather.itboy.net/api/weather/city/" + cityCode;
        String result = HttpUtil.get(url);
        Map<String, String> resultMap = new HashMap<>();
        resultMap.put("result", result);
        return resultMap;
    }

}
